import user_declare from "../orc/orc_declare/user_declare";
import event_manager from "../orc/orc_event";

const {ccclass, property} = cc._decorator;

@ccclass
export default class NewClass extends cc.Component {

    hall_view:fgui.GComponent; 

    test_index:number = 0;
    

    onLoad () {    
        console.log('game_hall');    

        fgui.UIConfig.modalLayerColor = new cc.Color(0,0,0,178);  //有效  
        fgui.GRoot.create();
        fgui.UIConfig.modalLayerColor = new cc.Color(0,0,0,178);  //无效


        this.hall_view = fgui.UIPackage.createObject("hall","hall").asCom;    //包名,组件名
        this.hall_view.makeFullScreen();
        fgui.GRoot.inst.addChild(this.hall_view);

        orc.orc_event.add_listener(user_declare.event_id.userinfo_event,this.userinfo_handle.bind(this))

        orc.orc_data.memory_data.user_info['money'] = 5;
        this.hall_view.getChild('n34').asLoader.url = 'http://cdn.img.iheyman.com/webroot/cartoon/upload/ads/local/20201110/7c7fb276ce148f5f3275b57e53e853a2.jpg';
          
        //console.log('',this.hall_view.node)
        //this.hall_view.getChild('n7').asCom.getChild('n8').asTextField.text = String(orc.orc_data.memory_data.user_info['money']);
        //this.hall_view.node.getChildByName('level_number').getComponent(cc.Label).string = String(orc.orc_data.memory_data.user_info['money'])
        this.hall_view.getChild('n7').asCom.getChild('n8').asTextField.setVar('exp','0').flushVars();
        this.hall_view.getChild('n36').asButton.onClick(this.btn_package,this);

        if(cc.winSize.height > 1334)
        {
            let aGroup = this.hall_view.getChild("top_node").asGroup;
            let cnt = this.hall_view.numChildren;
            for(let i=0;i<cnt;i++)
            {
                if(this.hall_view.getChildAt(i).group==aGroup)
                {
                    this.hall_view.getChildAt(i).node.y -= (cc.winSize.height - 1334)/2;
                }
            }
        }

       
       
    }

    userinfo_handle(){
        console.log('userinfo_handle');
        this.hall_view.getChild('n7').asCom.getChild('n8').asTextField.setVar('exp','144400').flushVars();
    }

    btn_package(){
        let body = {};
        body['name'] = 'cmd';
        body['age'] = 18;
        orc.orc_win.win_open('win_package',body);
        // orc.orc_win.win_open('win_sex');
        // if (this._winB == null)
        //     this._winB = new win_sex();
        // this._winB.show();
        // orc.orc_win.win_open('win_sex');
        // console.log('show:',this.sex_view.isShowing);
        // this.sex_view.center();
        // this.sex_view.setPivot(0.5, 0.5);

        // this.sex_view.setScale(0.1, 0.1);        
        // fgui.GTween.to2(0.1, 0.1, 1, 1, 0.3)
        //     .setTarget(this.sex_view, this.sex_view.setScale)
        //     .setEase(fgui.EaseType.QuadOut)       
        // this.sex_view.show();
       
        // console.log('show:',this.sex_view.isShowing);


        // let win_content = fgui.UIPackage.createObject("window","win_sex").asCom;//包名,组件名
        // win_content.makeFullScreen();
        // win_content.center();
        
        // // fgui.GRoot.inst.addChild(win_content);
        
        // console.log(this.hall_view);

        //添加子节点成功。按键没反应
        // let node = cc.instantiate(this.win_sex);
        // let win_content = fgui.UIPackage.createObject("window","win_sex").asCom;//包名,组件名
        // win_content.makeFullScreen();
        // win_content.center();
        // node.addChild(win_content.node);
        // this.hall_view.node.addChild(node);


        //node.addChild(win_content.node);
        //this.hall_view.addChild(node);
        

        //fgui.GRoot.inst.addChild(win_content);
        //win_content.node.zIndex = 1000;
        //this.node.addChild(win_content.node);
        //orc.orc_win.win_open('win_sex');
        // this.test_index++;
        // if(this.test_index%2 == 0)
        // {
        //     this.hall_view.getChild('n34').asLoader.url = 'http://cdn.img.iheyman.com/webroot/cartoon/upload/ads/local/20201110/70ea363e0779a0bc94f1ba2e0c47077b.jpg';
        // }
        // else
        // {
        //     this.hall_view.getChild('n34').asLoader.url = 'http://cdn.img.iheyman.com/webroot/cartoon/upload/ads/local/20201110/7c7fb276ce148f5f3275b57e53e853a2.jpg';
        // }

        //窗口系统1、0
        /*
        if(this.sex_view)
        {
            fgui.GTween.to2(0.1, 0.1, 1, 1, 0.3)
                .setTarget(this.sex_view, this.sex_view.setScale)
                .setEase(fgui.EaseType.QuadOut)
            this.sex_view.show();
        }   
        else
        {
            this.sex_view = new fgui.Window();
            this.sex_view.contentPane = fgui.UIPackage.createObject("window","win_sex").asCom;//包名,组件名
            this.sex_view.center();
            
            this.sex_view.setPivot(0.5, 0.5);
            this.sex_view.setScale(0.1, 0.1);
            fgui.GTween.to2(0.1, 0.1, 1, 1, 0.3)
                .setTarget(this.sex_view, this.sex_view.setScale)
                .setEase(fgui.EaseType.QuadOut)

                this.sex_view.show();
        }      
        */

        // console.log(win.node.width,win.node.height);
        // win.setPosition(cc.winSize.width/2 - win.node.width /2,cc.winSize.height/2 - win.node.height/2);
        //win.contentPane.getChild('').

        //fgui.UIConfig.modalLayerColor = new cc.Color(0,0,0,0.3);
        
        
        //let win = 
        
    }

}
